import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import iView from "iview";
import { getToken } from "@/utils/auth";
import request from "@/utils/request";
import * as API from "@/service/api";
import * as utils from "@/utils/utils";
import "iview/dist/styles/iview.css";

Vue.use(iView);

Vue.config.productionTip = false;

Vue.prototype.API = API;
Vue.prototype.$http = request;
Vue.prototype.$utils = utils;

//路由全局守卫
router.beforeEach((to, from, next) => {
  if (to.name === "Login") return next();
  const token = getToken();
  if (token) return next();
  next({ name: "Login" });
});

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount("#app");
